/*zhaoyihang
 * 用于解析serverconf
 * */
#include "threadPool.h"

char** tokenConf(char *serverconf) {
    static char *conf[3]; // 将 conf 数组定义为静态变量
    FILE *fp_conf = fopen(serverconf, "r");
    char str[1024];
    
    if (fp_conf == NULL) {
        printf("Failed to open file\n");
        return NULL;
    }
    
    if (fgets(str, 1024, fp_conf) == NULL) {
        printf("Failed to read file\n");
        fclose(fp_conf);
        return NULL;
    }
    
    fclose(fp_conf);
    
    char *token = strtok(str, " ");
    int i = 0;
    
    while (token != NULL && i < 3) {
        conf[i] = strdup(token); // 使用 strdup() 函数动态分配内存
        ++i;
        token = strtok(NULL, " ");
    }
    
    if (i < 3) {
        printf("Invalid file content\n");
        free(conf[0]);
        free(conf[1]);
        free(conf[2]);
        return NULL;
    }
    
    return conf;
}
